package com.mengtian_tech.tju.dataquery.api.task;

import java.math.BigInteger;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.mengtian_tech.tju.dataquery.api.service.AsyncDateService;
import com.mengtian_tech.tju.dataquery.api.service.GateDataHandleService;
import com.mengtian_tech.tju.dataquery.api.service.PersonVisitLogService;

@Component
public class AsyncPersonVisitTask {

	@Autowired
	PersonVisitLogService personVisitLogService;
	
	@Autowired
	GateDataHandleService gateDataHandleService;
	

	@Autowired
	AsyncDateService asyncDateService;
	
	/**
	 * 道闸数据每隔20分钟增量获取
	 */
	@Scheduled(cron = "0 */20 * * * ? ")
	public void run() {
		int total = 0;
		int count = personVisitLogService.aysncPersonVisitLog();
		while(count > 0) {
			total+= count;
			count = personVisitLogService.aysncPersonVisitLog();
			
		}
		
		//同步完成后，更新汇总报表
		try {
			BigInteger lastId =  this.gateDataHandleService.handleRpt(null);
			while( lastId != null) {
				 lastId = this.gateDataHandleService.handleRpt(lastId);
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		asyncDateService.updateDate("03", total);
	}
	
}
